//==============================================================================
#ifndef _CENTITY_H_
    #define _CENTITY_H_

#include <vector>
#include <string>
#include "Area.h"
#include "Animation.h"
#include "Camera.h"
#include "FPS.h"
#include "Surface.h"
#include "Client.h"

//==============================================================================
//Enum to identify the type of entity.
enum {
	ENTITY_TYPE_GENERIC = 0,
	ENTITY_TYPE_PLAYER,
	ENTITY_TYPE_ENEMY,
	ENTITY_TYPE_OBSTACLE,
	ENTITY_TYPE_PLAYERSPELL
};

//==============================================================================
enum {
	ENTITY_FLAG_NONE 	= 0,
	ENTITY_FLAG_GRAVITY	= 0x00000001,
	ENTITY_FLAG_GHOST	= 0x00000002,
	ENTITY_FLAG_MAPONLY	= 0x00000004
};

//==============================================================================
class CEntity {
	public:
		static std::vector<CEntity*>    ProjectileList; //Define the vector to hold projectiles in.
		static std::vector<CEntity*>    PlayerList; //Define the vector to hold players in.
		static int mouseX; //MouseX position.
		static int mouseY; //MouseY position.
		char itemArray[5]; //Array containing the different items a player have.
		int targetX;
		int targetY;
	protected:
		
		SDL_Surface*	Surf_FrozenPlayer;

	public:
		
		bool exploded; //value used for checking if a projectile is exploded.
		CAnimation      Anim_Control;
		SDL_Surface*    Surf_Entity;
		int playerScore; //Hold the score of the player.
		int     castTime; //Players cast-time,this is modified by items.
		int playerDeaths; //Hold how many times the player have died.
		int maxHealth; //The max health of a player, this is modified by items.
		int castStart;
		std::string name; //The entity name.
		int castEnd;
		int spellID;
		int spellIdentifier;
		bool casting;
		float	X;
		float	Y;
		int		Width;
		int		Height;

		bool	MoveLeft; 
		bool	MoveRight;
		bool	Jump();
		int		damage;
		int		playerID; //Used for identifying which spell belongs to which player under cast( prevents collision with player)
		bool	CanJump;
		int		MaxJumpSpeed;
		bool	facingRight;
		bool	facingLeft;
		
		int castSpell1, castSpell2, castSpell3, castSpell4, castSpell5;

		bool frozen;
		int freezeTime;


		enum spell
		{
			SPELL_NONE = 0,
			SPELL_BASIC
		};

	public:
		int		Type;

		int		health;
		int		Flags;

		int oldTime;
		int newTime;

	protected:
		float	SpeedX;
		float	SpeedY;

		float	speedX;

		float	AccelX;
		float	AccelY;

	public:
		float	MaxSpeedX;
		float	MaxSpeedY;
		virtual void	CastProjectile(int identity);
	protected:
		int		CurrentFrameCol;
		int		CurrentFrameRow;

	protected:
		int		Col_X;
		int		Col_Y;
		int		Col_Width;
		int		Col_Height;

	public:
		CEntity();

		virtual ~CEntity();
		
		sf::Packet x;
	public:
		virtual bool OnLoad(char* File, int Width, int Height, int MaxFrames);

		virtual void OnLoop();

		virtual void OnRender(SDL_Surface* Surf_Display,int playerID);

		virtual void OnCleanup();

		virtual void OnAnimate();

		virtual bool OnCollision(CEntity* Entity); 

		virtual void RunCollision(CEntity* Entity);

		bool OnProjectileMove(int newX, int newY);

	public:
		void    OnMove(float MoveX, float MoveY);

		void 	StopMove();

		void flash();
	public:
		bool    Collides(int oX, int oY, int oW, int oH);

	private:
		bool 	PosValid(int NewX, int NewY);

		bool 	PosValidTile(CTile* Tile);

		bool 	PosValidEntity(CEntity* Entity, int NewX, int NewY);
};

//==============================================================================
class CEntityCol {
public:
	static std::vector<CEntityCol>	EntityColList;
	
public:
	CEntity* EntityA;
	CEntity* EntityB;

public:
	CEntityCol();
};

class NetworkCol {
public:
	static std::vector<NetworkCol>	NetworkEntityColList;
	
public:
	int A;
	int B;

public:
	NetworkCol();
};
//==============================================================================

#endif
